--[[
	Do not re-distribute or modify
	without permission of its author Shoop (Aka. Jakeb34).
-- ________________________________________________________________________________________________________________________________________
--]]




local mindcontrol = {} -- Parent window and main script

-- Plans 
--
-- Aim Target
-- Do a ped / vehicle / entity PedTab,PedCount check to find all entities -- for k,v in ipairs -- if PLAYER::IS_PLAYER_FREE_AIMING_AT_ENTITY(v)then ... etc...
-- PLAYER::IS_PLAYER_FREE_AIMING_AT_ENTITY

-- << MODULES >>

function mindcontrol.speedcheck()
	if(speed < 1)then
			
	else
		speed = speed - 1
	end
end



function mindcontrol.carbrake()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do 
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
	
			speed = ENTITY.GET_ENTITY_SPEED(v)
			for i = 1,60 do
				VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed)
				mindcontrol.speedcheck()
				ENTITY.SET_ENTITY_VELOCITY(v, 0, 0, 0)
			end
		end
	end
		
end

function mindcontrol.anger()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		PED.SET_PED_AS_ENEMY(v, true)
	end
		
end

function mindcontrol.calm()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		PED.SET_PED_AS_ENEMY(v, false)
	end
		
end




function mindcontrol.carexplode()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do 
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
			VEHICLE.EXPLODE_VEHICLE(v, true, true)
		end
	end
	
end

function mindcontrol.alarm()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do 
		VEHICLE.SET_VEHICLE_ALARM(v, true)
		VEHICLE.START_VEHICLE_ALARM(v)
	end
	
end

function mindcontrol.steerfault()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do 
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
			VEHICLE.SET_VEHICLE_OUT_OF_CONTROL(v, true, false)
			-- VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, 40)
		end
	end

end

function mindcontrol.forceforward()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
			speed = ENTITY.GET_ENTITY_SPEED(v)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 1)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 2)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 3)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 4)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 5)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 6)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 7)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 8)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 9)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 10)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 11)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 12)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 13)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 14)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 15)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 16)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 17)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 18)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 19)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 20)
		end
	end

end

function mindcontrol.burnout()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	
	for k,v in ipairs(VehTab)do 
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
			VEHICLE.SET_VEHICLE_BURNOUT(v, true)
		end
	end
	
end

function mindcontrol.jump()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		vehCheck = PED.IS_PED_IN_ANY_VEHICLE(v, false)
		if(vehCheck == false)then
			AI.TASK_JUMP(v, true)
		else
		end
	end
	
end

function mindcontrol.scare()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		vehCheck = PED.IS_PED_IN_ANY_VEHICLE(v, false)
		if(vehCheck == false)then
			AI.TASK_COWER(v, 20)
		else
		end
	end
	
end

function mindcontrol.destroyengine()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do 
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
			VEHICLE.SET_VEHICLE_ENGINE_HEALTH(v, 0)
		end
	end
	
end

function mindcontrol.ragdoll()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		PED.SET_PED_TO_RAGDOLL(v, 6, 20, 20, TRUE, TRUE, TRUE);
	end
		
end

function mindcontrol.disguise()
	local PedTab = {}
	local PedCount = {}
	local player = PLAYER.PLAYER_ID()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	defmdl = ENTITY.GET_ENTITY_MODEL(playerPed)
	
	for k,v in ipairs(PedTab)do
		local model = ENTITY.GET_ENTITY_MODEL(PedTab[1])
		PLAYER.SET_PLAYER_MODEL(player, model)
		PLAYER.CLEAR_PLAYER_WANTED_LEVEL(player) -- When you disguise you lose wanted level!
	end
end

function mindcontrol.removedis()
	local player = PLAYER.PLAYER_ID()
	PLAYER.SET_PLAYER_MODEL(player, initmodel)
end

function mindcontrol.slay()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		if(v == playerPed)then
		
		else
			ENTITY.SET_ENTITY_HEALTH(v, 0)
		end
	end
end

function mindcontrol.heal()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		ENTITY.SET_ENTITY_HEALTH(v, 100)
	end
end


-- << MODULES >>




function mindcontrol.init()

	mindcontrol.GUI = Libs["GUI"] -- Main, Parent window
	
	local playerPed = PLAYER.PLAYER_PED_ID()
	initmodel = ENTITY.GET_ENTITY_MODEL(playerPed)
	
	mindcontrol.GUI.addButton("Force Car Brakes",mindcontrol.carbrake,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Destroy Engine",mindcontrol.destroyengine,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Force accelerate",mindcontrol.forceforward,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Explode Cars",mindcontrol.carexplode,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Alarm Malfunction",mindcontrol.alarm,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Knockout Drivers",mindcontrol.steerfault,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Break Car Brakes",mindcontrol.burnout,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Make Peds Jump",mindcontrol.jump,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Scare Peds",mindcontrol.scare,nil,0,0.2,0.05,0.07) 
	--mindcontrol.GUI.addButton("Anger Peds",mindcontrol.anger,nil,0,0.2,0.05,0.07) 
	--mindcontrol.GUI.addButton("Calm Peds",mindcontrol.calm,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Ragdoll Peds",mindcontrol.ragdoll,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Disguise",mindcontrol.disguise,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Remove Disguise",mindcontrol.removedis,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Slay Peds",mindcontrol.slay,nil,0,0.2,0.05,0.07)
	
	-- Parent Window -- [Hide all at startup]
	mindcontrol.GUI.hidden = true
	
	Keys.SquareBrakLeft = 219 -- Some Custom Keys
	
	Keys.SquareBrakRight = 221
	
	Keys.Hash = 192
	
	Keys.Comma = 188
	
	Keys.FullStopNotPeriod = 190
	
	Keys.Col = 186
	
	Keys.BackSlash = 220
	
	

	Keys.abilityOne = Keys.Hash -- Force Car Brakes - /

	Keys.abilityTwo = Keys.Comma -- Destroy Engine - /
	
	Keys.abilityThree = Keys.FullStopNotPeriod -- Force accelerate - /
	
	Keys.abilityFour = Keys.Col -- Explode cars - /
	
	Keys.abilityFive = Keys.Insert -- Alarm Malfunction - /
	
	Keys.abilitySix = Keys.Delete -- Knockout Drivers - /
	
	Keys.abilitySeven = Keys.Down -- Break Car brakes - /
	
	Keys.abilityEight = Keys.Left -- Make peds jump - /
	
	Keys.abilityNine = Keys.Right -- Scare Peds - /
	
	Keys.abilityTen = Keys.BackSlash -- Ragdoll peds - /
	
	Keys.abilityEleven = Keys.Divide -- Disguise - /
	
	Keys.abilityTwelve = Keys.SquareBrakLeft -- Remove Disguise - /
	
	Keys.abilityThirteen = Keys.SquareBrakRight -- Slay Peds - /

end

-- Force Car Brakes
-- Destroy Engine
-- Force accelerate
-- Explode cars
-- Alarm Malfunction
-- Knockout Drivers
-- Break Car brakes
-- Make peds jump
-- Scare Peds
-- Ragdoll peds
-- Disguise
-- Remove Disguise
-- Slay Peds

function mindcontrol.tick()
	
mindcontrol.GUI.tick()


	local player = PLAYER.PLAYER_ID()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local deathcheck = PLAYER.IS_PLAYER_DEAD(player)

	Keys.menuopen = 191
	Keys.menuclose = 8
	
	if(deathcheck == true)then
		PLAYER.SET_PLAYER_MODEL(player, initmodel) -- Should fix a bug with player death causing freeze. -- Yep Fixes it
	else
	end

	if(get_key_pressed(Keys.menuopen))then
		mindcontrol.GUI.hidden = false

	elseif(get_key_pressed(Keys.menuclose))then
		mindcontrol.GUI.hidden = true
		
-- CHANGE THE KEYS HERE

-- Example:  abilityOne = Keys.Numpad0, View the Available keys below and swap Keys.F1 for something else. E.G. Keys.L. So it would look like:  abilityOne = Keys.L
		
		
	elseif(get_key_pressed(Keys.abilityOne))then
		mindcontrol.carbrake()
		
	elseif(get_key_pressed(Keys.abilityTwo))then
		mindcontrol.destroyengine()
		
	elseif(get_key_pressed(Keys.abilityThree))then
		mindcontrol.forceforward()
		
	elseif(get_key_pressed(Keys.abilityFour))then
		mindcontrol.carexplode()
		
	elseif(get_key_pressed(Keys.abilityFive))then
		mindcontrol.alarm()
	
	elseif(get_key_pressed(Keys.abilitySix))then
		mindcontrol.steerfault()
		
	elseif(get_key_pressed(Keys.abilitySeven))then
		mindcontrol.burnout()
		
	elseif(get_key_pressed(Keys.abilityEight))then
		mindcontrol.jump()
		
	elseif(get_key_pressed(Keys.abilityNine))then
		mindcontrol.scare()
		
	elseif(get_key_pressed(Keys.abilityTen))then
		mindcontrol.ragdoll()
		
	elseif(get_key_pressed(Keys.abilityEleven))then
		mindcontrol.disguise()
		
	elseif(get_key_pressed(Keys.abilityTwelve))then
		mindcontrol.removedis()
		
	elseif(get_key_pressed(Keys.abilityThirteen))then
		mindcontrol.slay()

--[[		
mindcontrol.carbrake - /
mindcontrol.destroyengine - /
mindcontrol.forceforward - /
mindcontrol.carexplode - /
mindcontrol.alarm - /
mindcontrol.steerfault - /
mindcontrol.burnout - /
mindcontrol.jump
mindcontrol.scare 

mindcontrol.ragdoll
mindcontrol.disguise
mindcontrol.removedis
mindcontrol.slay
--]]
		
		
	end
end


--[[

AVAILABLE KEYS

Keys.None = 0
Keys.LButton = 1
Keys.RButton = 2
Keys.Cancel = 3
Keys.MButton = 4
Keys.XButton1 = 5
Keys.XButton2 = 6
Keys.Back = 8
Keys.Tab = 9
Keys.LineFeed = 10
Keys.Clear = 12
Keys.Return = 13
Keys.ShiftKey = 16
Keys.ControlKey = 17
Keys.Menu = 18
Keys.Pause = 19
Keys.Capital = 20
Keys.KanaMode = 21
Keys.JunjaMode = 23
Keys.FinalMode = 24
Keys.HanjaMode = 25
Keys.Escape = 27
Keys.IMEConvert = 28
Keys.IMENonconvert = 29
Keys.IMEAceept = 30
Keys.IMEModeChange = 31
Keys.Space = 32
Keys.PageUp = 33
Keys.Next = 34
Keys.End = 35
Keys.Home = 36
Keys.Left = 37
Keys.Up = 38
Keys.Right = 39
Keys.Down = 40
Keys.Select = 41
Keys.Print = 42
Keys.Execute = 43
Keys.PrintScreen = 44
Keys.Insert = 45
Keys.Delete = 46
Keys.Help = 47
Keys.D0 = 48
Keys.D1 = 49
Keys.D2 = 50
Keys.D3 = 51
Keys.D4 = 52
Keys.D5 = 53
Keys.D6 = 54
Keys.D7 = 55
Keys.D8 = 56
Keys.D9 = 57
Keys.A = 65
Keys.B = 66
Keys.C = 67
Keys.D = 68
Keys.E = 69
Keys.F = 70
Keys.G = 71
Keys.H = 72
Keys.I = 73
Keys.J = 74
Keys.K = 75
Keys.L = 76
Keys.M = 77
Keys.N = 78
Keys.O = 79
Keys.P = 80
Keys.Q = 81
Keys.R = 82
Keys.S = 83
Keys.T = 84
Keys.U = 85
Keys.V = 86
Keys.W = 87
Keys.X = 88
Keys.Y = 89
Keys.Z = 90
Keys.LWin = 91
Keys.RWin = 92
Keys.Apps = 93
Keys.Sleep = 95
Keys.NumPad0 = 96
Keys.NumPad1 = 97
Keys.NumPad2 = 98
Keys.NumPad3 = 99
Keys.NumPad4 = 100
Keys.NumPad5 = 101
Keys.NumPad6 = 102
Keys.NumPad7 = 103
Keys.NumPad8 = 104
Keys.NumPad9 = 105
Keys.Multiply = 106
Keys.Add = 107
Keys.Separator = 108
Keys.Subtract = 109
Keys.Decimal = 110
Keys.Divide = 111
Keys.F1 = 112
Keys.F2 = 113
Keys.F3 = 114
Keys.F4 = 115
Keys.F5 = 116
Keys.F6 = 117
Keys.F7 = 118
Keys.F8 = 119
Keys.F9 = 120
Keys.F10 = 121
Keys.F11 = 122
Keys.F12 = 123
Keys.F13 = 124
Keys.F14 = 125
Keys.F15 = 126
Keys.F16 = 127
Keys.F17 = 128
Keys.F18 = 129
Keys.F19 = 130
Keys.F20 = 131
Keys.F21 = 132
Keys.F22 = 133
Keys.F23 = 134
Keys.F24 = 135
Keys.NumLock = 144
Keys.Scroll = 145
Keys.LShiftKey = 160
Keys.RShiftKey = 161
Keys.LControlKey = 162
Keys.RControlKey = 163
Keys.LMenu = 164
Keys.RMenu = 165
Keys.BrowserBack = 166
Keys.BrowserForward = 167
Keys.BrowserRefresh = 168
Keys.BrowserStop = 169
Keys.BrowserSearch = 170
Keys.BrowserFavorites = 171
Keys.BrowserHome = 172
Keys.VolumeMute = 173
Keys.VolumeDown = 174
Keys.VolumeUp = 175
Keys.MediaNextTrack = 176
Keys.MediaPreviousTrack = 177
Keys.MediaStop = 178
Keys.MediaPlayPause = 179
Keys.LaunchMail = 180
Keys.SelectMedia = 181
Keys.LaunchApplication1 = 182
Keys.LaunchApplication2 = 183
Keys.Oem1 = 186
Keys.Oemplus = 187
Keys.Oemcomma = 188
Keys.OemMinus = 189
Keys.OemPeriod = 190
Keys.OemQuestion = 191
Keys.Oemtilde = 192
Keys.OemOpenBrackets = 219
Keys.Oem5 = 220
Keys.Oem6 = 221
Keys.Oem7 = 222
Keys.Oem8 = 223
Keys.OemBackslash = 226
Keys.ProcessKey = 229
Keys.Packet = 231
Keys.Attn = 246
Keys.Crsel = 247
Keys.Exsel = 248
Keys.EraseEof = 249
Keys.Play = 250
Keys.Zoom = 251
Keys.NoName = 252
Keys.Pa1 = 253
Keys.OemClear = 254
Keys.KeyCode = 65535
Keys.Shift = 65536
Keys.Control = 131072
Keys.Alt = 262144
Keys.Modifiers = -65536

--]]

return mindcontrol